package com.example.board.controller;

import com.example.board.common.R;
import com.example.board.pojo.vo.NumberRate;
import com.example.board.pojo.vo.TopSaleAchievement;
import com.example.board.service.DistributorService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/")
@Api(tags = "经销商业绩看板", value = "经销商业绩看板")
@RequiredArgsConstructor
public class DistributorController {

    private final DistributorService distributorService;

    @ApiOperation("全国的")
    @PostMapping(value = "/distributor-board/nation-statics")
    public R getAllCity() {

        return R.ok(distributorService.getAllCityAmount());
    }

    @ApiOperation("客户增长数")
    @PostMapping(value = "/distributor-board/customer-inc")
    public R getCityNumberRate(String province, String region, String time, String teamName) {

        NumberRate cityOrderRate = null;
        try {
            cityOrderRate = distributorService.getCityNumberRate(province, region, time, teamName);

            return R.ok(cityOrderRate);

        } catch (ParseException e) {
            throw new RuntimeException(e);
        }

    }


    @ApiOperation("业务员业绩排行")
    @PostMapping(value = "/distributor-board/salesman-rank")
    public R getTopSale(String province, String region, String teamName,String startTime) {
        List<TopSaleAchievement> topSaleAchievement = distributorService.getTopSaleAchievement(province, region, teamName,startTime);
        Map<String,Object> map = new HashMap<>();
        map.put("chartData",topSaleAchievement);
        return R.ok(map);
    }

    @ApiOperation("客户返单率")
    @PostMapping(value = "/distributor-board/customer-re-rate")
    public R getCityOrderRate(String province, String region) {

        return R.ok(distributorService.getCityOrderRate(province, region));
    }

    @ApiOperation("订单增长")
    @PostMapping(value = "/distributor-board/order-inc")
    public R getCityOrderIncrease(String province, String region, String time,String teamName) throws ParseException {

        return R.ok(distributorService.getCityOrderIncrease(province, region, time,teamName));

    }


    @ApiOperation("总订单数")
    @PostMapping(value = "/distributor-board/order-total")
    public R getCityOrder(String province, String region, String targetOrder){
        return R.ok(distributorService.getCityOrder(province, region , targetOrder));
    }




}
